// import {series} from './request';
// import {xAxis} from './request';

// 基于准备好的dom，初始化echarts实例
//折线图容器
var myChartLine = echarts.init(document.getElementsByClassName('lineChart')[0]);
//饼状图容器
var myChartCircule = echarts.init(document.getElementsByClassName('circular')[0])
//柱状图容器
var myChartcolumn = echarts.init(document.getElementsByClassName('column')[0])

// 折线图数据
let seriesLine = JSON.parse(window.sessionStorage.getItem("seriesLine"));
let xAxisLine = JSON.parse(window.sessionStorage.getItem("xAxisLine"));
// 柱状图数据
let xAxisCircule = JSON.parse(window.sessionStorage.getItem("xAxisCircule"));
let seriesCircule = JSON.parse(window.sessionStorage.getItem("seriesCircule"));
// 饼状图数据
let circularData = [];
for (let i = 0; i < seriesCircule.length; i++) {
    let centerData = {
        "name": xAxisCircule[i],
        "value": seriesCircule[i]
    }
    circularData.push(centerData)
}


// 指定折线图的配置项和数据
var optionLine = {
    title: {
        left: 'center',
        text: '曲线图数据展示'
    },
    xAxis: {
        type: 'category',
        data: [...xAxisLine]
    },
    yAxis: {
        type: 'value',
        name: '人'
    },
    series: [{
        smooth: true,
        type: 'line',
        data: [...seriesLine],
        //显示折点数据
        label: {
            show: true,
            position: "top"
        },
        areaStyle: {
            color: {
                type: 'linear',
                colorStops: [ // 渐变颜色
                    {
                        offset: 0,
                        color: '#f3f6fe',
                    },
                ],
                global: false,
            },
        },
    }]
};

// 指定饼状图的配置项和数据
var option = {
    title: {
        text: '饼状图数据展示',
        left: 'center'
    },
    tooltip: {
        trigger: 'item'
    },
    legend: {
        orient: 'vertical',
        left: 'left'
    },
    series: [{
        name: 'Access From',
        type: 'pie',
        radius: '50%',
        data: circularData,
        emphasis: {
            itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
        }
    }]
};
// 指定柱状图的配置项和数据
optionColumn = {
    title: {
        text: '柱状图数据展示',
        left: 'center'
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow'
        }
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: [{
        type: 'category',
        data: xAxisCircule,
        axisTick: {
            alignWithLabel: true
        }
    }],
    yAxis: [{
        type: 'value'
    }],
    series: [{
        name: 'Direct',
        type: 'bar',
        barWidth: '60%',
        data: seriesCircule
    }]
};

myChartCircule.setOption(option)

myChartLine.setOption(optionLine);

myChartcolumn.setOption(optionColumn);


